import numpy as np
import torch

A = np.arange(25).reshape(5, 5)
print(A)

print("遍历每一行，找到2索引所在的一列")
B = A[..., 2]
print(B)

print("遍历每一行，找到索引小于2的列")
C = A[..., :2]
print(C)

print("遍历每行，::2表示步长为2，即0，2，4列")
D = A[..., ::2]
print(D)

print("::2表示取间隔步长为2的取行数据，遍历每列")
E = A[::2, ...]
print(E)

print("相当于插入维度，即reshape(A,[1,4,4])")
F2 = A[None, ...]
print(F2)

print("torch.cat用法")
X = np.arange(16 * 3).reshape(3, 4, 4)
print(X)

print("行和列步长间隔都为2")
X1 = X[..., ::2, ::2]
print(X1)

print("行和列步长间隔都为2，行的起始位置为1")
X2 = X[..., 1::2, ::2]
print(X2)

print("行和列步长间隔都为2，列的起始位置为1")
X2 = X[..., ::2, 1::2]
print(X2)

X4 = torch.from_numpy(X)
print("原来为：")
print(X4)
print("reorg函数处理后：")
X4 = torch.cat([X4[..., ::2, ::2], X4[..., 1::2, ::2], X4[..., ::2, 1::2], X4[..., 1::2, 1::2]], 1)
print(X4)
